package serv

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

func AdminLogIndexCtrl(c *gin.Context) {
	if c.Request.Method == "POST" {
		var adminUserArr []map[string]any
		where := "1"

		param := GetJsonData(c)
		page := int(param["page"].(float64))
		limit := int(param["limit"].(float64))

		dbEngine.Table("f_log").Where(where).Limit(limit, (page-1)*limit).Find(&adminUserArr)
		cnt, _ := dbEngine.Table("f_log").Where(where).Count()

		c.JSON(200, ApiList{
			Status: 200,
			Data: ApiDataListObj{
				Total:       cnt,
				PerPage:     0,
				CurrentPage: 0,
				LastPage:    0,
				Data:        adminUserArr,
			},
		})
	} else {
		c.HTML(http.StatusOK, "admin-log-index.html", nil)
	}
}

func AdminLogDeleteCtrl(c *gin.Context) {
	param := GetJsonData(c)

	if param["id"] != nil {
		dbEngine.Table("f_log").Where("id in (?)", param["id"]).Delete()
		c.JSON(200, map[string]any{
			"status": 200,
			"msg":    "删除成功",
		})
	}
}
